require(['./config'],() => {
    require(['request','template','header','footer'],(req,template) => {
        class List{
            constructor(){
                this.getProdId()
            }
            getProdId(){
                // 通过地址栏 拿到prodId 然后发送请求
                // console.log(window)
                let str = window.location.search
                str = str.split('=')[1]
                // console.log(str)
                this.getListData(str)
            }
            getListData(prodId){
                req.getListProdData(prodId)
                    .then(res => {
                        // console.log(res)
                        if(res.code === 200){
                            const { categories,items } = res.data
                            this.createTabs(categories)
                            this.createList(items)
                        }
                    })
            }
            // 渲染旁侧列表
            createTabs(categories){
                // console.log(categories)
                const html = $('#collection_menu_shelf_top').html()
                $('#collection_menu_shelf_top').html(html + template('listTabsTemplate',{categories}))
            }
            createList(prodList){
                console.log(prodList)
                const { list } = prodList
                $('.products_content').html(template('prodListTemplate',{list}))
            }
        }
        return new List()
    })
})